﻿//DealCards.as
//-----------------------------------------
//Paul is working on this...
//card images were obtained from http://freeware.esoterica.free.fr/html/freecards.html
//might need to give cred..
//-----------------------------------------
package 
{
	import flash.display.*;
	
	import flash.xml.XMLDocument;
    import flash.xml.XMLNode;
    import flash.xml.XMLNodeType; 
		
	import flash.events.MouseEvent;
	import Card;
	
	public class DealCards extends MovieClip
	{
		//variables
		//private static constant player1_CardDown_y:Number = 200;
		//private static constant player1_CardUp_y:Number = 190;
		//private static constant player1_Card1_x:Number = 20;
		private var nextCardWidth = 10;
		private var cardSuit="";
		private var cardNum="";
		private var cardDesc="";
		private var thisCard:Array;
		private var cardList:Array;
		
		private var movingCard:Card;
		private var cardOffset:Number;
		private var cardOrigin:Number;
		
		//=================================================================
		//constructor
		//=================================================================
		public function DealCards()
		{
			//create array containing all the cards-----------------------------------------
			cardList = new Array();
			
			init();
		}//end of DealCards() Constructor
		//=================================================================
		//=================================================================
		public function init():void
		{//draw cards to the screen-----------------------------------------
		/*
			for(var x:int =0;x<13;x++){
				
				cardList[x] = new Card();
				var thisCard:Card = cardList[x];
				thisCard.x = 20 + nextCardWidth;
				//thisCard.y = 220 ;
				//cardList[x] = thisCard;
				cardList[x].setY(220);
				cardList[x].y=220;
				cardList[x].setCard("x: "+x);
				//cardList[x].setX(20 + nexCardWidth);
				//trace("x: "+x+" xpos: "+ cardList[x].x);
				this.addChild(cardList[x]);
				nextCardWidth += 30;
				
				//listeners for the mouse events-----------------------------------------
				cardList[x].addEventListener(MouseEvent.MOUSE_OVER, overHandler);
				cardList[x].addEventListener(MouseEvent.MOUSE_OUT, outHandler);
				cardList[x].addEventListener(MouseEvent.CLICK, clickHandler);
				cardList[x].addEventListener(MouseEvent.MOUSE_DOWN, downHandler);
			}//end of for
			addEventListener(MouseEvent.MOUSE_UP, upHandler);
			*/
		}
		//=================================================================
		public function overHandler(event:MouseEvent):void
		{
			
			if(event.target.getHeld() == false)
			{
   				event.target.y=200;
			}
			
		}
		//=================================================================
		public function outHandler(event:MouseEvent):void
		{
			
			if(event.target.getHeld() == false)
			{
   				event.target.y=220;
			}
		}
		//=================================================================
		public function clickHandler(event:MouseEvent):void
		{
			//Mouse.hide();
			event.target.hold();
    		trace(event.target.getCard());
		}
		//=================================================================
		//custom cursor

		/*onMouseMove = function() {
		 myMouse._x = _xmouse;
		 myMouse._y = _ymouse;
		}*/
		//=================================================================
		public function downHandler(event:MouseEvent):void
		{
			movingCard = Card(event.currentTarget);
			cardOffset = stage.mouseX - movingCard.x;
			cardOrigin = stage.mouseX - cardOffset;
			addEventListener(MouseEvent.MOUSE_MOVE, cardDrag);

		}
		//=================================================================
		public function upHandler(event:MouseEvent):void
		{
			removeEventListener(MouseEvent.MOUSE_MOVE, cardDrag);
			snapInPlace();
		}
		//=================================================================
		function cardDrag(event:MouseEvent):void
		{
			movingCard.x = stage.mouseX - cardOffset;
			event.updateAfterEvent();
		}
		//=================================================================
		function snapInPlace():void
		{
			if(false)
			{
				//place card in new position(snapped), resort hand
			}
			else
			{
				movingCard.x = cardOrigin;
			}
		}
		//=================================================================
	}//end of class
}//end of package